hey guys this is probably an easy fix but i was wounderingif any1 has answers for why
Code:
printf("\nThere is no employee with that I.D. number\n");
always prints even when its not meant to
heres where it is happening
Code:
void employees_index_search(struct employees employee[], int n)
{
int indexsearch, i;
printf("Enter the employee I.D. for who you would like to see information on:\n");
scanf(" %d", &indexsearch);
for(i=0;i<n;i++)
{
if(indexsearch == employee[i].EmpId)
{
printf("\n%d\t\t%s\t\t$%.2f\t\t", employee[i].EmpId, employee[i].Name, employee[i].Salary);
}
}
if(indexsearch != employee[0].EmpId || employee[1].EmpId || employee[2].EmpId)
{
printf("\nThere is no employee with that I.D. number\n");
}
}
and here is my full code:
Code:
#include <stdio.h>
#include <stdlib.h>
struct employees {
int EmpId;
char Name[25];
float Salary;
}s[3];
void read_employees(struct employees employee[], int n)
{
int i;
for(i=0;i<n;i++)
{
printf("Enter employee %d's ID:\n", i+1);
scanf("%d", &employee[i].EmpId);
printf("Enter employee %d's name: \n", i+1);
scanf(" %s", employee[i].Name);
printf("Enter employee %d's salary:\n$", i+1);
scanf(" %f", &employee[i].Salary);
}
printf("\n\n");
}
void print_employees(struct employees employee[], int n)
{
int i;
printf("\t\t---printing data---\n");
for (i=0;i<n;i++)
{
printf("%d\t\t%s\t\t$%.2f\t\t", employee[i].EmpId, employee[i].Name, employee[i].Salary);
if(employee[i].Salary <4000)
{
printf("Level A");
}
if(employee[i].Salary >5000)
{
printf("Level B");
}
printf("\n");
}
}
void employees_total_salary(struct employees employee[], int n, float *total)
{
int i;
for(i=0;i<n;i++)
{
*total = *total + employee[i].Salary;
}
}
void employees_index_search(struct employees employee[], int n)
{
int indexsearch, i;
printf("Enter the employee I.D. for who you would like to see information on:\n");
scanf(" %d", &indexsearch);
for(i=0;i<n;i++)
{
if(indexsearch == employee[i].EmpId)
{
printf("\n%d\t\t%s\t\t$%.2f\t\t", employee[i].EmpId, employee[i].Name, employee[i].Salary);
}
}
if(indexsearch != employee[0].EmpId || employee[1].EmpId || employee[2].EmpId)
{
printf("\nThere is no employee with that I.D. number\n");
}
}
int main()
{
int n =3;
float total;
read_employees(s, n);
print_employees(s, n);
employees_total_salary(s, n, &total);
printf("\ntotal salary = $%.2f\n", total);
employees_index_search(s, n);
system("pause");
return 0;
}
thankyou, also if you have any other advice it would be well recieved